2020-2021 Sunseeker Telemetry and Lighting System
adc12_a_ex5_repeatedSingle.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
65 //******************************************************************************
66 
67 #include "driverlib.h"
68 
69 #define Num_of_Results 8
70 
71 volatile uint16_t results[Num_of_Results];
72 //Needs to be global in this
73 //example. Otherwise, the
74 //compiler removes it because it
75 //is not used for anything.
76 
77 void main (void)
78 {
79  //Stop Watchdog Timer
80  WDT_A_hold(WDT_A_BASE);
81 
82  //Enable A/D channel A0
83  GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P6,
84  GPIO_PIN0
85  );
86 
87  //Initialize the ADC12_A Module
88  /*
89  * Base address of ADC12_A Module
90  * Use internal ADC12_A bit as sample/hold signal to start conversion
91  * USE MODOSC 5MHZ Digital Oscillator as clock source
92  * Use default clock divider of 1
93  */
94  ADC12_A_init(ADC12_A_BASE,
95  ADC12_A_SAMPLEHOLDSOURCE_SC,
96  ADC12_A_CLOCKSOURCE_ADC12OSC,
97  ADC12_A_CLOCKDIVIDER_1);
98 
99  ADC12_A_enable(ADC12_A_BASE);
100 
101  /*
102  * Base address of ADC12_A Module
103  * For memory buffers 0-7 sample/hold for 256 clock cycles
104  * For memory buffers 8-15 sample/hold for 4 clock cycles (default)
105  * Enable Multiple Sampling
106  */
107  ADC12_A_setupSamplingTimer(ADC12_A_BASE,
108  ADC12_A_CYCLEHOLD_256_CYCLES,
109  ADC12_A_CYCLEHOLD_4_CYCLES,
110  ADC12_A_MULTIPLESAMPLESENABLE);
111 
112  //Configure Memory Buffer
113  /*
114  * Base address of the ADC12_A Module
115  * Configure memory buffer 0
116  * Map input A0 to memory buffer 0
117  * Vref+ = AVcc
118  * Vref- = AVss
119  * Memory buffer 0 is not the end of a sequence
120  */
121  ADC12_A_configureMemoryParam param = {0};
122  param.memoryBufferControlIndex = ADC12_A_MEMORY_0;
123  param.inputSourceSelect = ADC12_A_INPUT_A0;
124  param.positiveRefVoltageSourceSelect = ADC12_A_VREFPOS_AVCC;
125  param.negativeRefVoltageSourceSelect = ADC12_A_VREFNEG_AVSS;
126  param.endOfSequence = ADC12_A_NOTENDOFSEQUENCE;
127  ADC12_A_configureMemory(ADC12_A_BASE ,&param);
128 
129  //Enable memory buffer 0 interrupt
130  ADC12_A_clearInterrupt(ADC12_A_BASE,
131  ADC12IFG0);
132  ADC12_A_enableInterrupt(ADC12_A_BASE,
133  ADC12IE0);
134 
135  //Enable/Start first sampling and conversion cycle
136  /*
137  * Base address of ADC12_A Module
138  * Start the conversion into memory buffer 0
139  * Use the repeated single-channel
140  */
141  ADC12_A_startConversion(ADC12_A_BASE,
142  ADC12_A_MEMORY_0,
143  ADC12_A_REPEATED_SINGLECHANNEL);
144 
145  //Enter LPM4, Enable interrupts
146  __bis_SR_register(LPM4_bits + GIE);
147  //For debugger
148  __no_operation();
149 }
150 
151 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
152 #pragma vector=ADC12_VECTOR
153 __interrupt
154 #elif defined(__GNUC__)
155 __attribute__((interrupt(ADC12_VECTOR)))
156 #endif
157 void ADC12ISR (void)
158 {
159  static uint8_t index = 0;
160 
161  switch (__even_in_range(ADC12IV,34)){
162  case 0: break; //Vector 0: No interrupt
163  case 2: break; //Vector 2: ADC overflow
164  case 4: break; //Vector 4: ADC timing overflow
165  case 6: //Vector 6: ADC12IFG0
166  //Move results
167  results[index] =
168  ADC12_A_getResults(ADC12_A_BASE,
169  ADC12_A_MEMORY_0);
170 
171  //Increment results index, modulo;
172  //Set Breakpoint1 here and watch results[]
173  index++;
174 
175  if (index == 8){
176  index = 0;
177  }
178  case 8: break; //Vector 8: ADC12IFG1
179  case 10: break; //Vector 10: ADC12IFG2
180  case 12: break; //Vector 12: ADC12IFG3
181  case 14: break; //Vector 14: ADC12IFG4
182  case 16: break; //Vector 16: ADC12IFG5
183  case 18: break; //Vector 18: ADC12IFG6
184  case 20: break; //Vector 20: ADC12IFG7
185  case 22: break; //Vector 22: ADC12IFG8
186  case 24: break; //Vector 24: ADC12IFG9
187  case 26: break; //Vector 26: ADC12IFG10
188  case 28: break; //Vector 28: ADC12IFG11
189  case 30: break; //Vector 30: ADC12IFG12
190  case 32: break; //Vector 32: ADC12IFG13
191  case 34: break; //Vector 34: ADC12IFG14
192  default: break;
193  }
194 }
MPU_initThreeSegmentsParam param
volatile uint16_t results[Num_of_Results]
void main(void)
#define Num_of_Results
void ADC12ISR(void)
__no_operation()